package com.uvnos4j.matilda.commons.dto;

import lombok.Data;

import java.io.Serializable;

/**
 * 响应结果封装
 * <p>
 * Description:响应结果封装
 * </p>
 *
 * @author Guo.wl
 * @version v1.0.0
 * @see com.uvnos4j.matilda.commons.dto
 * @since 2020-08-31 22:39:51
 */
@Data
public class Result implements Serializable {

    private static final long serialVersionUID = 3468352004150968551L;

    private String status;

    private String msg;

    private Object data;

    private Result(String status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功
     *
     * @param data 数据
     * @return result
     */
    public static Result success(Object data) {
        return success("成功", data);
    }

    /**
     * 成功
     *
     * @param msg  成功消息
     * @param data 数据
     * @return result
     */
    public static Result success(String msg, Object data) {
        return retMsg("200", msg, data);
    }

    /**
     * 失败
     *
     * @param msg 错误信息
     * @return result
     */
    public static Result fail(String msg) {
        return fail("500", msg);
    }

    /**
     * 失败
     *
     * @param status 状态码
     * @param msg    错误信息
     * @return result
     */
    public static Result fail(String status, String msg) {
        return retMsg(status, msg, null);
    }

    /**
     * 返回信息
     *
     * @param status 状态码
     * @param msg    提示信息
     * @param data   数据
     * @return result
     */
    public static Result retMsg(String status, String msg, Object data) {
        return new Result(status, msg, data);
    }

}